home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: jhewett@ix.netcom.com (Jerry Hewett)
- Newsgroups: comp.lang.c++
- Subject: Did I Miss Something?
- Date: Wed, 03 Apr 96 18:51:36 GMT
- Organization: Netcom
- Message-ID: <N.040396.105136.51@ix.netcom.com>
- NNTP-Posting-Host: tem-ca1-13.ix.netcom.com
- X-NETCOM-Date: Wed Apr 03 12:55:08 PM CST 1996
- X-Newsreader: Quarterdeck Message Center [2.00]
-
- I recently discovered that if you want to throw code for Win95 you need a lot
- more than six years of experience writing C code for Win3.x, so I've been
- trying to (re)teach myself C++ over the past couple of days using the Coronado
- Enterprises C++ TUTOR (more about this below).
-
- My question revolves around the following code snippet taken from one of the
- tutorial programs; specifically, what the heck is going on with "char *line_of_
- text"? Where is the memory for the data being pointed to coming from? My
- theory is in the comment below.
-
- Feel free to tell me how clueless I'm being. ;-)
-
- ----<snip>----
-
- // OBJSTRNG.CPP, from Chapter 6 - More Encapsulation.
-
- class box {
- int length;
- int width;
- char *line_of_text;
- public:
- box(char *input_line);
- void set(int new_length, int new_width);
- int get_area(void);
- };
-
- /*
- Just guessing, but here goes...
-
- Below is the constructor for "box". The object doesn't exist until the
- constructor creates it. Since a pointer to a "known" fixed-length string
- is being passed to the constructor, the compiler determines the amount of
- memory required to store the string "small box ", allocates space for it
- in the object, and copies it into this space.
-
- Once the object passes out of scope this "magically" created chunk of
- memory allocation disappears along with the object... (???)
- */
-
- box::box(char *input_line)
- {
- length = 8;
- width = 8;
- line_of_text = input_line;
- }
-
- main()
- {
- box small("small box ");
-
- }
-
- ----<snip>----
-
- So far (the past three days) I've learned more from the Coronado Enterprises
- C++ TUTOR than from all of the books I bought that were supposed to help me
- migrate from C to C++ *and* the seminars/courses I've attended on OOP/OOD. I
- should also confess that it's been more than a couple of years since my first
- exposure to OOP; I took the class, but didn't have any contracts that required
- C++ and/or objects, so nearly all of it vanished into the haze...
-
- This tutorial is definitely worth the $15 shareware fee as far as I can tell.
- Now I just need to find a contract that will put it to use while it's all
- occupying neural space near the forebrain! 8-)
-
- Jerry H.
-
-
-